#include "l3.h"
#include "prot_icmp.h"
#include "prot_tcp.h"

#define L3_ENTRY_NUM  256

struct l3entry {
  uint8_t protocol;
  l3_func_t rx_func;
  l3_func_t tx_func;
};

static bool l3_rx_default(struct llbuf *ll)
{
  return false;
}

static bool l3_tx_default(struct llbuf *ll)
{
  return false;
}

struct l3entry l3config[] = {
  {.protocol=IPPROTO_IP, .rx_func = l3_rx_default, .tx_func = l3_tx_default},
  {.protocol=IPPROTO_ICMP, .rx_func = icmp_rx, .tx_func = icmp_tx},
  {.protocol=IPPROTO_TCP, .rx_func = tcp_rx, .tx_func = tcp_tx},
};


static uint8_t l3addr[L3_ENTRY_NUM];

bool l3_rx(struct llbuf *ll)
{
  uint8_t config = l3addr[ll->protocol];
  return l3config[config].rx_func(ll);
}

bool l3_tx(struct llbuf *ll)
{
  return false;
}

bool l3_init(void)
{
  memset(&l3addr[0], 0, sizeof(l3addr));
  unsigned int i;
  for (i = 0; i < sizeof(l3config)/sizeof(l3config[0]);i++) {
    l3addr[l3config[i].protocol] = (uint8_t)i;
  }
  return true;
}

void l3_deinit(void)
{
}



